<!DOCTYPE html>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";//http://192.168.1.1:8080/abc/abc.jsp
%>
<base href="<%=basePath%>">
<html lang="zh">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="description" content="">
    <meta name="keywords" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>登录页面</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="stylesheet" href="user/css/amazeui.min.css">
    <link rel="stylesheet" href="user/css/app.css">
</head>

<body>
<div class="am-g myapp-login">
    <div class="myapp-login-logo-block">
        <div class="myapp-login-logo">
            <%--<i class="am-icon-jsfiddle"></i>--%>
        </div>
        <div class="myapp-login-logo-text">
            <div class="myapp-login-logo-text">
                XX<span>保健医院</span>
                <div class="info">Find the best places in town.</div>
            </div>
        </div>

        <div class="login-font">
            <!--<i>Log In </i> or <span> Sign Up</span>-->
        </div>
        <div class="am-u-sm-10 login-am-center">
            <form class="am-form">
                <fieldset>
                    <div class="am-form-group">
                        <input type="text" class="" name="userAccount" id="userAccount" placeholder="用户名">
                    </div>

                    <div class="am-form-group">
                        <input type="password" class="" name="userPwd" id="userPwd" placeholder="密码">
                    </div>
                    <div class="am-form-group">
                        <input type="text" class="" name="keyCode" id="keyCode" placeholder="验证码">
                    </div>
                    <div>
                        <img src="imageAction/imgCode.action" id="imgCode" onclick="getCode1()">
                        <span onclick="getCode1()" style="color:  white;">看不清？</span><br>
                    </div>
                    <p><button type="button" class="am-btn am-btn-default" onclick="checkLogin()">登录</button></p>
                </fieldset>
            </form>
        </div>
    </div>
</div>
<script src="user/js/jquery.min.js"></script>
<script src="user/js/amazeui.min.js"></script>
<script src="user/js/app.js"></script>
<script>
    function getCode1(){
        var imgCode = document.getElementById("imgCode");
        imgCode.src = "imageAction/imgCode.action?p="+Math.random();
    }

    function checkLogin() {
        if ($("#userAccount").val() == "") {
            alert("用户名不能为空");
            return;
        }
        if ($("#userPwd").val() == "") {
            alert("密码不能为空");
            return;
        }
        var userAccount = $("#userAccount").val();
        var userPwd = $("#userPwd").val();
        var keyCode = $("#keyCode").val();

        $.ajax({
            url : "frontUser/checkLogin.action",
            data : {
                "userAccount" : userAccount,
                "userPwd" : userPwd,
                "keyCode" : keyCode
            },
            type : "post",
            dataType : "text",
            success : function (res) {
                if(res == "success" ){
                    window.alert("登录成功！！");
                    // window.location.href="frontUser/userLogin.action";
                    window.location.href="index.jsp";

                }else if(res == "loginError"){
                    window.alert("帐号或密码错误！！")
                    // window.location.href="index.jsp";
                }else if(res == "stateError"){
                    window.alert("帐号状态不可用！！")
                }else if(res == "codeError"){
                    window.alert("验证码错误！！")
                }else if (res == "existence"){
                    window.alert("该帐号已经登录，请确认后再重试！！")
                }
            }
        });
    }
</script>
</body>
</html>